/*
 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
 */

#include <stdlib.h>
#include <aos/aos.h>
#include <yoc/uservice.h>
#include <yoc/eventid.h>

#include <drv/gpio.h>
#include <pin_name.h>
#include <pin.h>

#include <devices/devicelist.h>
#include <devices/led.h>
#include <devices/devicelist.h>
#include <ipc.h>

#include "app_init.h"

#define TAG  "app"

#include <pin.h>

#define LPM_WAIT_CMD (0X01)
#define LPM_SERVER_ID (0X02)

static void board_pinmux_config(void)
{
#ifdef APP_DEBUG
    drv_pinmux_config(CONSOLE_TXD, 0);
    drv_pinmux_config(CONSOLE_RXD, 0);
    drv_pinmux_config(CONSOLE_TXD_FUNC, 0);
    drv_pinmux_config(CONSOLE_RXD_FUNC, 0);
#endif
}

void board_init(void)
{
    board_pinmux_config();
}

static void _ipc_process(ipc_t *ipc, message_t *msg, void *priv)
{
    if (msg->command == LPM_WAIT_CMD) {
        *(volatile uint32_t *)0xe000e140 = 0x10;  //配置唤醒源为mcc
        LOGD(TAG,"cpu1 lpm enter");
        ipc_message_ack(ipc, msg, AOS_WAIT_FOREVER);
        asm("wait");
        LOGD(TAG,"cpu1 lpm leave");
    }
}

static void lpm_init(void)
{
    ipc_t *ipc = ipc_get(0);

    ipc_add_service(ipc, LPM_SERVER_ID, _ipc_process, NULL);
}

void main()
{
    board_yoc_init();

    extern int adicore_cp_init();
    extern int eqicore_cp_init();
    extern int resicore_cp_init();
    extern int aeficore_cp_init();
    extern int ffticore_cp_init();
    adicore_cp_init();
    resicore_cp_init();
    aeficore_cp_init();
    ffticore_cp_init();
    lpm_init();
    while (1) {
        aos_msleep(20*1000);
    }
}
